	@include('admin.head')
	<link rel="stylesheet" type="text/css" href="<%url('css/compiled/elements.css')%>">
	<div class="container">
		<div class="row">
			@include('admin.side')
			<div class="col-md-10" id="content-wrapper">
				<div class="row">

					<div class="col-lg-12">
						<div class="clearfix">
							<h1 class="pull-left">前台基础配置</h1>
						</div>
						<div class="row">

							<div class="col-lg-6">
								<div class="main-box clearfix" preload>
									<h2>应用技术配置
										<button style="float:right" id="techs"  type="button" class="btn btn-primary btn_add">添加</button>
									</h2>
									<div class="table-responsive">
										<table class="table table-striped table-hover">
											<thead>
												<tr>
													<th>
														<input type="checkbox" value=""  class="checkAll">
													</th>
													<th><span>名称</span></th>
												</tr>
											</thead>
											<tbody id="techList">
											</tbody>
										</table>
									</div>
									<button type="button" id="deltechs" class="btn btn-danger">删除</button>
								</div>
							</div>

							<div class="col-lg-6">
								<div class="main-box clearfix" preload>
									<h2>投资模式配置
										<button style="float:right" id="invest"  type="button" class="btn btn-primary btn_add">添加</button>
										<input type="hidden" class="type">
									</h2>
									<div class="table-responsive">
										<table class="table table-striped table-hover">
											<thead>
												<tr>
													<th>
														<input type="checkbox" value=""  class="checkAll">
													</th>
													<th><span>名称</span></th>
												</tr>
											</thead>
											<tbody id="investList">
											</tbody>
										</table>
									</div>

									<button type="button" id="delInvest"  class="btn btn-danger">删除</button>
								</div>
							</div>

							<div class="col-lg-6">
								<div class="main-box clearfix" preload>
									<h2>应用主体配置
										<button style="float:right" id="applyList"  type="button" class="btn btn-primary btn_add">添加</button>
									</h2>
									<div class="table-responsive">
										<table class="table table-striped table-hover">
											<thead>
												<tr>
													<th>
														<input type="checkbox" value=""  class="checkAll">
													</th>
													<th><span>名称</span></th>
												</tr>
											</thead>
											<tbody id="energyList">
											</tbody>
										</table>
									</div>
									<button type="button" id="delMainbody" class="btn btn-danger">删除</button>
								</div>
							</div>

							<div class="col-lg-6">
								<div class="main-box clearfix" preload>
									<h2>用户角色配置
										<!-- <button style="float:right" id="applyList"  type="button" class="btn btn-primary btn_add">添加</button> -->
									</h2>
									<div class="table-responsive">
										<table class="table table-striped table-hover">
											<thead>
												<tr>
													<!-- <th>
														<input type="checkbox" value=""  class="checkAll">
													</th> -->
													<th><span>名称</span></th>
												</tr>
											</thead>
											<tbody id="userList">
											</tbody>
										</table>
									</div>
									<!-- <button type="button" id="" class="btn btn-danger">删除</button> -->
								</div>
							</div>

							<div class="col-lg-6">
								<div class="main-box clearfix" preload>
									<h2>系统设置
										<button style="float:right"  type="button" class="btn btn-primary" id="btn_addSystem">添加</button>
									</h2>
									<div class="table-responsive">
										<table class="table table-striped table-hover">
											<thead>
												<tr>
													<th>
														<input type="checkbox" value=""  class="checkAll">
													</th>
													<th><span>名称</span></th>
													<th><span>值</span></th>
													<th><span></span></th>
												</tr>
											</thead>
											<tbody id="systemList">
											</tbody>
										</table>
									</div>
									<button type="button" id="delSystem" class="btn btn-danger">删除</button>
								</div>
							</div>

							<div class="col-lg-6">
								<div class="main-box" preload>
									<div class="row cf nestable-lists">
										<div class="col-xs-12">
											<h4>领域配置 <button type="button" id="addDomain" class="btn btn-primary btn_add">添加一级分类</button></h4>
											<ol class="dd-list" id="lingyu">
											</ol>
										</div>
									</div>
								</div>
							</div>


						</div>
					</div>
					<style>
					#cover{
						width: 100%;
						height: 100%;
						position: absolute;
						background: rgba(0,0,0,0.5);
						display: none;
					}
					.form_hide{
						margin: 100px 200px;
					}
					.edit{
						/*border: none;*/
						line-height: 24px;
						font-size: 16px;
						background: rgba(255,255,255,0);
					}
					</style>
					<div id="cover">
						<div class="col-lg-6 form_hide">
							<div class="main-box" id="addSubDomain" style="display:none;left:50%;top:50%;position:fixed;width:500px;margin-left:-250px;margin-top:-120px;height:240px;">
								<div role="form">
									<div class="form-group">
										<label>添加多个用 “|”或 回车换行 分隔开</label>
										<textarea class="form-control" id="subDomains" rows="5"></textarea>
									</div>
									<button  type="button" class="btn btn-primary" id="sub_domain_add">添加</button>
									<button  type="button" class="btn btn-primary" id="sub_domain_cancel">取消</button>
								</div>
							</div>
							<div class="main-box" id="addType" style="display:none;left:50%;top:50%;position:fixed;width:500px;margin-left:-250px;margin-top:-120px;height:240px;">
								<div role="form">
									<div class="form-group">
										<label>添加多个用 “|”或 回车换行 分隔开</label>
										<textarea class="form-control" id="exampleTextarea" rows="5"></textarea>
									</div>
									<button  type="button" class="btn btn-primary" id="btn_sub">添加</button>
									<button  type="button" class="btn btn-primary" id="btn_cancel">取消</button>
								</div>
							</div>
 							<div class="main-box" id="addSystem" style="display:none;left:50%;top:50%;position:fixed;width:500px;margin-left:-250px;margin-top:-120px;height:240px;">
								<div role="form-horizontal">
									<div class="form-group">
										<label>名称:</label>
										  <input class="form-control input_size" name="key" placeholder="" type="text">
										<label>值:</label>
										  <input class="form-control input_size" name="value" placeholder="" type="text">
									</div>
									<div class="form-group">
										<button  type="button" class="btn btn-primary" id="btn_add_system">添加</button>
										<button  type="button" class="btn btn-primary" id="btn_cancel_system">取消</button>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>


	@include("admin.footer")

	@include("admin.common")

<!-- 应用技术模板 -->
<script type="text/html" id="tech_temp">
{%each list as value}
<tr>
<td><input type="checkbox" name="techs" value="{%value.id}"></td>
<td><input class="edit" name="techVal" old="{%value.cate_name}" tid="{%value.id}" value="{%value.cate_name}" type="text"></td>
</tr>
{%/each}
</script>

<!-- 投资模式表 -->
<script type="text/html" id="invest_temp">
{%each list as value}
<tr>
<td><input type="checkbox" name="invests" value="{%value.id}"></td>
<td><input class="edit" name="invVal" old="{%value.name}" tid="{%value.id}" value="{%value.name}" type="text"></td>
</tr>
{%/each}
</script>

<!-- 应用主体表 -->
<script type="text/html" id="apply_temp">
 {%each list as value}
 <tr>
 <td><input type="checkbox" name="applys" value="{%value.id}"></td>
 <td><input class="edit" name="applyVal" old="{%value.name}" tid="{%value.id}" value="{%value.name}" type="text"></td>
 <tr>
 {%/each}
 </script>

<!-- 用户角色 -->
<script type="text/html" id="user_temp">
 {%each list as value}
 <tr>
 <td><input class="edit" name="userVal" old="{%value.role_name}" tid="{%value.id}" value="{%value.role_name}" type="text"></td>
 <tr>
 {%/each}
 </script>

 <!-- 系统设置 -->
<script type="text/html" id="pro_temp">
	{%each list as value}
	<tr>
		<td><input type="checkbox" name="systems" value="{%value.id}"></td>
		<td><input class="edit" name="sysKey" value="{%value.key}" type="text"></td>
		<td><input class="edit" name="sysValue" value="{%value.value}" type="text"></td>
		<th><button type="button" class="btn btn-primary editSys" tid="{%value.id}">修改</button></th>
	<tr>
	{%/each}
</script>

  <!--领域表-->

<script type="text/javascript">
var url = "<%url('admin')%>/"
var curl = '';
var que = "que";

var isloading = false;


//外添加
$('.btn_add').bind("click", function(){
	$("#addType").show();
	$('#cover').show();
})
//取消
$('#btn_cancel').click(function(){
	$("#addType").hide();
	$('#cover').hide();
	$('#exampleTextarea').val('');
})
//系统设置添加
$("#btn_addSystem").bind("click", function(){
	$("#addSystem").show();
	$('#cover').show();

})

$("#btn_cancel_system").bind("click", function(){
	$("#addSystem").hide();
	$('#cover').hide();

})


$("#btn_add_system").click(function(){
	var k = $("#addSystem input[name='key']").val().trim();
	var v = $("#addSystem input[name='value']").val().trim();
	if(k == '' || v == ''){
		warning("", "名称或值不能为空");
		return;
	}
	if(isloading){
		return;
	}
	isloading = true;
	$.post(url + "config/add_system", {key : k, value : v}, function (data){
		isloading=false;
		if(data.success){
			$("#addSystem input[name='key']").val('');
			$("#addSystem input[name='value']").val('');
			success("", "添加成功");
			setTimeout(function(){
				window.location.reload();
			}, 1000)
		}
	})

})



$("#techs").click(function(){
	curl = "config/add_tech";
})

$("#invest").click(function(){
	curl = "config/add_invest";
})

$("#applyList").click(function(){
	curl = "config/add_body" ;
})


$("#addDomain").click(function(){
	curl = "config/add_domains";
})


$('#btn_sub').bind('click',function(){
	var data = $('#exampleTextarea').val().trim();
	if(!data){
		warning("不能为空");
		return;
	}
	if(isloading){
		return;
	}
	isloading = true;
	$.post(url + curl,{data:data, parent_id: parent_id},function(data){
		isloading=false;
		if(data.success){
			$('#exampleTextarea').val('');
			success("", "添加成功");
			setTimeout(function(){
				window.location.reload();
			}, 1000)
		}
	})
})


// 应用技术

$("#deltechs").bind("click", function(){
	var techs = [];
	$("#techList").find("input[name='techs']:checked").each(function(k, v){
		techs.push($(v).val());
	})
	$.post(url + 'config/delete_tech',  {techs : techs},function(data){
		 success("", "删除成功");
		 setTimeout(function(){
		 window.location.reload();
		 }, 1000)


	})
})


$.getq(que, url + 'config/get_tech',function(data){
	if(data.success){
		var html = template("tech_temp", {list : data.data});
		$('#techList').html(html);
		removeLoading($($('#techList').parents(".main-box")[0]));
		$("#techList").find("input[name='techVal']").bind("blur", function(){
			var _this = $(this);
			var oldName = $(this).attr("old").trim();
			var name = $(this).val().trim();
			var tid = $(this).attr("tid");
			if(name != oldName){
				$.post(url + 'config/update_tech',{tid : tid , name : name},function(data){
					if(data.success){
						_this.attr("old", data.data);
						success("", "修改成功");
					}
				})
			}
		})
	}
})

//投资表
$.getq(que, url + 'config/get_invest',function(data){
	if(data.success){
		 var html = template("invest_temp",{list : data.data});
		 $('#investList').html(html);
		 removeLoading($($('#investList').parents(".main-box")[0]));
		$('#investList').find("input[name='invVal']").bind("blur",function(){
			var _this = $(this);
			var oldName = $(this).attr("old").trim();
			var name = $(this).val();
			var tid = $(this).attr("tid");
			if(name != oldName){
				$.post(url + 'config/update_invest',{tid:tid,name:name},function(data){
					if(data.success){
						_this.attr("old", data.data);
						success("","修改成功");
					}
				})
			}
		})
	}
})


$("#delInvest").bind("click",function(){
	var  inves = [];
	$("#investList").find("input[name='invests']:checked").each(function(k,v){
		inves.push($(v).val());
	})
	$.post(url +'config/delete_invest' , {inves : inves },function(data){
		if(data.success){
			success("", "删除成功");
			setTimeout(function(){
				window.location.reload();
			})
		}
	})
})

//应用主体
$("#delMainbody").bind("click", function(){
	var applys = [];
	$("#energyList").find("input[name='applys']:checked").each(function(k, v){
		applys.push($(v).val());
	})
	$.post(url + 'config/delete_body', {applys : applys},function(data){
		if(data.success){
			success("", "删除成功");
			setTimeout(function(){
				window.location.reload();
			})
		}
	})
})

$("#delSystem").bind("click", function(){
	var systems = [];
	$("#systemList").find("input[name='systems']:checked").each(function(k, v){
		systems.push($(v).val());
	})
	$.post(url + 'config/delete_system', {systems : systems},function(data){
			if(data.success){
				success("", "删除成功");
				setTimeout(function(){
					window.location.reload();
				})

			}
	})
})





$.getq(que, url + 'config/get_body',function(data){
	if(data.success){
		var html = template("apply_temp", {list : data.data});
		$('#energyList').html(html);
		removeLoading($($('#energyList').parents(".main-box")[0]));
		$("#energyList").find("input[name='applyVal']").bind("blur", function(){
			var _this = $(this);
			var oldName = $(this).attr("old").trim();
			var name = $(this).val();
			var tid = $(this).attr("tid");
			if(name != oldName){
				$.post(url + 'config/update_body',{tid : tid , name : name},function(data){
					if(data.success){
						_this.attr("old", data.data);
						success("", "修改成功");
					}
				})
			}
		})
	}
})

//领域表
var parent_id;
$.getq(que, url + "config/get_domains", function (data){
	if(data.success){
		str = str_list(data);
		$('#lingyu').html(str);
		removeLoading($($('#lingyu').parents(".main-box")[0]));
		$(".add_son_domain").bind("click", function (){
			curl = "config/add_domains";
			parent_id = $(this).attr("pid");
			$('#cover').show();
			$("#addSubDomain").show();
		});

		$("#sub_domain_add").bind("click", function(){
			var data = $('#subDomains').val().trim();
			if(!data){
				warning("二级领域不能为空");
				return;
			}
			if(isloading){
				return;
			}
			isloading = true;
			$.post(url + curl,{data:data, parent_id: parent_id},function(data){
				isloading=false;
				if(data.success){
					$('#subDomains').val('');
					success("", "添加成功");
					setTimeout(function(){
						window.location.reload();
					}, 1000)
				}
			})
		});

		$("#sub_domain_cancel").bind("click", function(){
			$('#cover').hide();
			$("#addSubDomain").hide();
		});
		$(".btn_delete").bind('click',function(){
			_this = $(this);
			confirm('','确定要删除吗？','warning',function (data){
				if(data == 1){
					var cid = _this.attr('cid');
					$.post(url + 'config/delete_domains',{cid:cid},function(resp){
						if(resp.success){
							_this.parents('li').remove();
						}else{
						}
					})
				}
			})
		})

		$("#lingyu input[class='editName']").bind("blur", function(){
			var _this = $(this);
			var oldName = $(this).attr("old").trim();
			var name = $(this).val().trim();
			var tid = $(this).attr("tid");
			if(name != oldName){
				$.post(url + "config/update_domains", {tid : tid, name : name}, function(data){
					if(data.success){
						_this.attr("old", data.data);
						success("","修改成功");
					}
				})
			}

		})

	}
})

function str_list(data){
	var str = '';
	$.each(data.data,function(k,v){

		if(v.parent_id != 0){
			str += '<li class="dd-item dd-item-list" son="'+v.parent_id+'" style="margin-left:50px;" data-id="13">';
			str += '<div class="dd-handle-list" style="z-index:0;"><i class="fa fa-bars"></i></div>';
			str += '<div class="dd-handle"><input old="'+v.cate_name+'" tid="'+v.id+'" class="editName" style="border:none;background:rgba(255,255,255,0)" value="'+v.cate_name+'" type="text">';
			str += '<div class="nested-links">';
			str += '<a href="javascript:;" cid="'+v.id+'" class="nested-link btn_delete"><i class="glyphicon glyphicon-minus"></i></a>';
			str += '</div></div></li>';
		}else{
			str += '<li class="dd-item dd-item-list" parent="'+v.id+'" data-id="13">';
			str += '<div class="dd-handle-list" style="z-index:0;"><i class="fa fa-bars"></i></div>';
			str += '<div class="dd-handle"><input old="'+v.cate_name+'" tid="'+v.id+'" class="editName" style="border:none;background:rgba(255,255,255,0)" value="'+v.cate_name+'" type="text">';
			str += '<div class="nested-links">';
			str += '<a href="javascript:;" pid="'+v.id+'" class="nested-link add_son_domain"><i class="glyphicon glyphicon-plus"></i></a>';
			str += '<a href="javascript:;" cid="'+v.id+'" class="nested-link btn_delete"><i class="glyphicon glyphicon-minus"></i></a>';
			str += '</div></div></li>';
		}
	})
	return str;
}


//用户角色
$.getq(que, url + 'config/get_role',function(data){
	if(data.success){
		var html = template("user_temp", {list : data.data});
		$('#userList').html(html);
		removeLoading($($('#userList').parents(".main-box")[0]));
		$("#userList").find("input[name='userVal']").bind("blur", function(){
			var _this = $(this);
			var oldName = $(this).attr("old").trim();
			var role_name = $(this).val();
			var tid = $(this).attr("tid");
			if(role_name != oldName){
				$.post(url + 'config/update_role',{tid : tid,role_name : role_name},function(data){
					if(data.success){
						_this.attr("old", data.data);
						success("", "修改成功");
					}
				})
			}
		})
	}
})

//系统设置
$.getq(que, url + 'config/get_system',function(data){
		if(data.success){
		var html = template("pro_temp", {list : data.data});
		$('#systemList').html(html);
		removeLoading($($('#systemList').parents(".main-box")[0]));
		$(".editSys").bind("click", function(){
			var _this = $(this);
			var tid = _this.attr("tid");
			var k = _this.parents("tr").find("input[name='sysKey']").val().trim();
			var v = _this.parents("tr").find("input[name='sysValue']").val().trim();
			$.post(url + 'config/update_system',{tid : tid, key : k, value : v},function(data){
				if(data.success){
					success("", "修改成功");
				}
			})
		})
	}
})

$('.checkAll').click(function(){
	$(this).parents('table').find('tbody').find('input[type=checkbox]').prop('checked', $(this).prop('checked'));
})

</script>



</body>
</html>